package com.novelot.plugin.allinone.setting;

import com.intellij.openapi.options.Configurable;

import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.Nullable;

import javax.swing.JComponent;

public class ApplicationSettingsConfigurable implements Configurable {
    private AppSettingsComponent mySettingsComponent;

    // A default constructor with no arguments is required because this implementation
    // is registered as an applicationConfigurable EP

    @Nls(capitalization = Nls.Capitalization.Title)
    @Override
    public String getDisplayName() {
        return "All In One";
    }

    @Override
    public JComponent getPreferredFocusedComponent() {
        return mySettingsComponent.getPreferredFocusedComponent();
    }

    @Nullable
    @Override
    public JComponent createComponent() {
        mySettingsComponent = new AppSettingsComponent();
        return mySettingsComponent.getPanel();
    }

    @Override
    public boolean isModified() {
        AppSettingsState settings = AppSettingsState.getInstance();
        boolean modified = !mySettingsComponent.getHanisdkDir().equals(settings.hanisdkDir);
        modified |= mySettingsComponent.getMomoDir() != settings.momoDir;
        return modified;
    }

    @Override
    public void apply() {
        AppSettingsState settings = AppSettingsState.getInstance();
        settings.hanisdkDir = mySettingsComponent.getHanisdkDir();
        settings.momoDir = mySettingsComponent.getMomoDir();
    }

    @Override
    public void reset() {
        AppSettingsState settings = AppSettingsState.getInstance();
        mySettingsComponent.setHanisdkDir(settings.hanisdkDir);
        mySettingsComponent.setMomoDir(settings.momoDir);
    }

    @Override
    public void disposeUIResources() {
        mySettingsComponent = null;
    }
}
